<!-- TMS订单管理 - 综合表单页面 -->
<template>
  <div class="page-container">
    <page_breadcrumb :getKeyMethod="init_table_model" @change="change_table_model" pageOption />

    <ex_super_table_page v-bind="option" ref="SuperTablePage" @selection-change="e => selection = e">
    </ex_super_table_page>

    <report_anomaly ref="report_anomaly" :orderTypeList="['TRANSPORT']"
      :formDisabled="['orderType', 'customerId', 'orderNo']" @afterSubmitSuccess="reload()" />
  </div>
</template>
<script>
import report_anomaly from '@/component/dialog/report_anomaly.vue'

import superTablePageFunction from '@/mixin/super-table-page-function';

import page_table_model_manage from '@/mixin/page_table_model_manage';
import emitOnFunction from '@/mixin/emit-on-function';
let emitKey = 'tms>line_manage'
export default {
  title: 'label_order_list',
  mixins: [superTablePageFunction, emitOnFunction(emitKey), page_table_model_manage],
  components: { report_anomaly },
  data() {
    return {

      selection: [],
      option: {
        search: {
          model: [
            { key: 'trackNumber', label: 'label_tms_receipt_shipping_order_number' },
            { key: 'refOrderCode', label: 'label_tms_track_order_platform_no' },
            { key: 'receiptUserName', label: 'label_tms_track_consignee_name' },
            { key: 'taskType', label: 'label_fms_subject_order_type', type: 'select', enum: 'TrackTaskTypeEnum' },
            { key: 'status', label: 'label_tms_receipt_order_status', type: 'select', enum: 'TmsOrderStatusEnum',listHandler:(e)=>e.filter(it=>!['GET_TRACK_NUMBER','GET_TRACK_FAIL'].includes(it)) },
            { key: 'deliveryAddress', label: 'label_tms_receipt_commence_address' },
            { key: 'receiptAddress', label: 'label_tms_waybill_destination' },
          ],
        },
        actionExtra: [
          {
            label: 'label_create_plan', attrs: { type: "primary" }, click: () => {
              if (this.selection.length == 0) {
                return this.$message.error(this.$tt('tip_please_select_order'))
              }
              this.$router.push({ path: '/page/tms/order/track_create_plan', query: { emitKey, selection: this.selection.map(it => `${it.id}`).join(',') } });
            }
          },
          {
            label: 'label_withdrawal_plan', click: () => {
              if (this.selection.length == 0) {
                return this.$message.error(this.$tt('tip_please_select_order'))
              }

              this.revokeGeneratePlan(this.selection)
            }
          },
          {
            label: "label_trajectory_import",
            auth: "/page/tms/track/track_import",
            click: () => {
              this.$router.push('/page/tms/track/track_import')
            }
          },
          {
            label: 'label_download_attachment', click: () => {
              if (this.selection.length == 0) {
                return this.$message.error(this.$tt('tip_please_select_order'))
              }
              this.exportAttach()
            }
          },

          /*{
            label: 'label_confirm_completion', attrs: {}, click: () => {
              this.$noFunction()
            }
          },*/
          { label: 'label_export', click: this.exportExcel },

        ],

        table: {
          url: "/tms-api/task/TmsOrderInfoRpc/selectByPage.json",
          model: this.init_table_model(),
        }
      },
    };
  },
  methods: {
    option_table_model() {
      return [
        { type: 'selection', clickToggle: true, },
        {
          type: 'expandDesc', 'width': 100,
          expandDesc: {
            class: "desc_flex_row",
            column: 4, border: true, direction: 'vertical', labelClassName: 'flex_cell', contentClassName: 'flex_cell',
            model: [],
          },
        },
        { key: 'trackNumber', label: 'label_tms_receipt_shipping_order_number', 'min-width': 160, 'show-overflow-tooltip': true, },
        { key: 'refOrderCode', label: 'label_tms_receipt_order_platform_number', 'min-width': 160, 'show-overflow-tooltip': true, },
        { key: 'customerName', label: 'label_tms_track_customer_name', 'width': 150, 'show-overflow-tooltip': true, },

        {
          key: 'status', label: 'label_order_status', 'width': 100,
          formatter: (r, c, v, i) => this.$enumShow(v, "TmsOrderStatusEnum")
        },

        { key: 'deliveryAddress', label: 'label_tms_receipt_commence_address', 'min-width': 150, 'show-overflow-tooltip': true, },
        { key: 'receiptAddress', label: 'label_tms_waybill_destination', 'min-width': 150, 'show-overflow-tooltip': true, },
        { key: 'routeName', label: 'label_tms_line_route_name', 'width': 150, 'show-overflow-tooltip': true, },

        { key: 'totalBoxCount', label: 'label_tms_track_pcs', 'width': 80, keyShow: 'expandDesc', },
        { key: 'totalQuantity', label: 'label_tms_track_pkgs', 'width': 80, keyShow: 'expandDesc', },
        { key: 'totalWeight', label: 'label_tms_track_weight', 'width': 80, keyShow: 'expandDesc', },
        { key: 'totalVolume', label: 'label_tms_track_volume', 'width': 80, keyShow: 'expandDesc', },
        { key: 'receiptUserName', label: 'label_tms_track_consignee', 'width': 100, 'show-overflow-tooltip': true, keyShow: 'expandDesc', },
        { key: 'receiptContacts', label: 'label_tms_track_contact', 'width': 100, 'show-overflow-tooltip': true, keyShow: 'expandDesc', },
        { key: 'requireCompleteTime', label: 'label_tms_track_planned_comp_time', keyShow: 'expandDesc', 'width': 120, formatter: (r, c, v, i) => this.$dateFormat(v), },
        { key: 'gmtCreate', label: 'label_create_time', keyShow: 'expandDesc', 'width': 120, formatter: (r, c, v, i) => this.$dateFormat(v), },
        { key: 'gmtModify', label: 'label_update_time', keyShow: 'expandDesc', 'width': 120, formatter: (r, c, v, i) => this.$dateFormat(v), },
        { key: 'creator', label: 'label_create_user', keyShow: 'expandDesc', 'width': 100, 'show-overflow-tooltip': true, },
        { key: 'modifier', label: 'label_modify_user', keyShow: 'expandDesc', 'width': 100, 'show-overflow-tooltip': true, },
        {
          type: 'operate', width: 200, operate: [
            {
              type: 'more',
              items: [
                { label: 'label_view_detail', click: (row) => this.clickDetail(row) },
                {
                  label: "label_tms_waybill_check_track",
                  click: (row) => {
                    this.$router.push({ path: '/page/tms/track/track_list', query: { trackNumber: row.trackNumber, } })
                  }
                },
                {
                  label: 'label_report_exception', auth: "tms_anomaly_report", click: (row) => {
                    this['$refs']['report_anomaly'].showNew({
                      data: {
                        orderType: 'TRANSPORT',
                        orderNo: row.trackNumber,
                        customerId: row.customerId,
                        customerCode: row.customerCode,
                        customerName: row.customerName,

                      },
                      onlySetData: true,
                    })
                    // this.$refs.reportAnomalyDialogRef.$refs['formDialog'].show(row, { setData: true }, this.$tt('label_report_exception'))
                  }
                },
              ]
            }

          ]
        }
      ]
    },
    revokeGeneratePlan(selection) {
      this.$msgbox_table({
        note: this.$tt("label_tms_track_cancel_sel_order"),
        tableProp: {
          data: selection,
          model: [
            { key: 'trackNumber', label: 'label_tms_receipt_shipping_order_number', 'min-width': 120, 'show-overflow-tooltip': true, },
            { key: 'refOrderCode', label: 'label_tms_receipt_order_platform_number', 'min-width': 120, 'show-overflow-tooltip': true, }
          ],
        },
      }, { type: 'warning', customClass: 'dialog_small' })
        .then(() => {
          this.$ajax({
            url: '/tms-api/task/TmsOrderInfoRpc/revokeGeneratePlan.json',
            method: 'post', type: 'json',
            loading: true,
            data: {
              trackIds: selection.map(it => {
                return it.id
              }),
            },
            success: (responseData) => {
              this.$message.success(this.$tt('tip_submit_success'))
              this.reload()
            },
            complete: () => {
            }
          });
        }).catch(() => {
        });

    },
    clickDetail(row) {
      this.$router.push({ path: '/page/tms/order/track_detail', query: { id: row.id, trackNumber: row.trackNumber } })
    },
    exportExcel() {
      this.$downloadFile({
        loading: true,
        type: 'json',
        url: '/tms-api/task/TmsOrderInfoRpc/exportExcel.json',
        data: {
          trackIds: this.selection.map(it => it.id),
          ...this.getSuperTablePage().getSearchFormData()
        },
      })
    },
    exportAttach() {
      let trackIds = []
      this.selection.forEach(item => {
        trackIds.push(item.id)
      })
      this.$downloadFile({
        loading: true,
        method: 'post',
        data: {
          trackIds
        },
        url: `/tms-api/task/TmsOrderInfoRpc/zipDownload.json`,
      })
    },

  }
};

</script>
<style></style>
